<template>
  <div class="tab-bar-item" @click="itemClick">
    <div v-if="isActive"><slot name="item-img-active"></slot></div>
    <div v-else><slot name="item-img"></slot></div>
    <div :style="activeStyle"><slot name="item-text"></slot></div>
  </div>
</template>

<script>
export default {
  name: 'TabBarItem',
  data(){
    return {

    }
  },
  computed:{
    isActive(){
      return this.$route.path.indexOf(this.path) !==-1
    },
    activeStyle(){
      return this.isActive ? { color:this.activeColor }: ''
    }
  },
  props: {
    path: {
      type:String,
      default:'/home'
    },
    activeColor: {
      type:String,
      default:'#ffc500'
    }
  },
  methods: {
    itemClick() {
      this.$router.push(this.path);
    }
  },
}
</script>

<style lang="scss" scope>
.tab-bar-item{
  flex: 1;
  text-align: center;
  height: 49px;
  display:flex;
  flex-wrap:wrap;
  div {
    width:100%;
  }
  p{
    margin:0;
    font-size: 15px;
  }
  img{
    width:21px;
  }
} 
</style>
